<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class UserCollection extends Model
{
    public static function getGoods($currentPage,$perPage){
        $uid = getUid();

        $list = self::where(['user_id'=>$uid])->order('create_time','desc')->paginate(['page'=>$currentPage,'list_rows'=>$perPage]);
        $goods = [];
        if($list){
            $list = $list->toArray();
            if($list['data']){
                foreach($list['data'] as $k=>$v){
                    $item = ActivityGoods::find($v['activity_goods_id']);
                    if($item){
                        $goods['data'][] = $item->toArray();
                    }
                }
            }else{
                $goods['data'] = [];
            }
            $goods['total'] = $list['total'];
            $goods['per_page'] = $list['per_page'];
            $goods['current_page'] = $list['current_page'];
            $goods['last_page'] = $list['last_page'];
        }else{
            $goods = $list;
        }

        return $goods;
    }

}
